#include <iostream>

using namespace std;

int main(){
	int h,m,s,ss;
	char ch;
	ss=0;
	cin>>h>>m>>s>>ch;

	if(ch =='P'){
		h=h+12;
	}
	ss=
	cout<<ss;
	return 0;
}
